#pragma once
#include <vector>

template<typename T>
class ObjectMgr
{
	friend class GameApplication;
private:
	typename std::vector<T> vec;
	typename std::vector<T>::iterator it;
public:
	ObjectMgr(void);
	~ObjectMgr(void);
	void New(T m);
	void UpdateAll();
	void DrawAll(HDC hdc);
	void CleanUp();
	void SetScroll( int ax, int ay );
};

template<typename T>
ObjectMgr<T>::ObjectMgr(void)
{
}

template<typename T>
ObjectMgr<T>::~ObjectMgr(void)
{
	CleanUp();
}

template<typename T>
void ObjectMgr<T>::CleanUp()
{
	for(it = vec.begin(); it != vec.end();it++)
	{
		T m = (*it);
		delete m;				
		//it = vec.erase(it);
	}
	vec.clear();
}

template<typename T>
void ObjectMgr<T>::DrawAll( HDC hdc )
{
	for(UINT i=0; i<vec.size(); ++i)
		vec[i]->Draw(hdc);
}

template<typename T>
void ObjectMgr<T>::UpdateAll()
{
	for(it = vec.begin(); it != vec.end();)
	{
		if( (*it)->hp <= 0 && !(*it)->bExplosion)
		{
			T m = (*it);
			delete m;				
			it = vec.erase(it);
		}
		else
		{
			(*it)->Update();
			it++;
		}
	}
}

template<typename T>
void ObjectMgr<T>::New( T m )
{
	vec.push_back(m);
}

template<typename T>
void ObjectMgr<T>::SetScroll( int ax, int ay )
{
	for(UINT i=0; i<vec.size(); ++i)
	{
		vec[i]->pos.x+=ax;
		vec[i]->pos.y+=ay;
	}
}